package edu.whu.demo.config;

import edu.whu.demo.job.ClearSchedule;
import edu.whu.demo.job.CrawlerJob;
//import edu.whu.demo.job.MessageJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JobConfig {

    @Bean
    public JobDetail clearJob(){

        JobDetail JobDetail = JobBuilder.newJob(ClearSchedule.class)
                .storeDurably() //必须调用该方法，添加任务
                .build();
        return JobDetail;
    }

    @Bean
    public Trigger clearTrigger(){
        //每天24时爬取信息
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 1/5 * * * ?");

        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(clearJob())
                .withSchedule(cronScheduleBuilder) //对触发器配置任务
                .build();

        return trigger;
    }

    @Bean
    public JobDetail crawlerDetail(){

        JobDetail JobDetail = JobBuilder.newJob(CrawlerJob.class)
                .storeDurably() //必须调用该方法，添加任务
                .build();
        return JobDetail;
    }

    @Bean
    public Trigger crawlerTrigger(){
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 25 20 * * ?"); //配置任务频率

        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(crawlerDetail())
                .withSchedule(cronScheduleBuilder) //对触发器配置任务
                .build();

        return trigger;
    }

//    @Bean
//    public JobDetail message(){
//
//        JobDetail JobDetail = JobBuilder.newJob(MessageJob.class)
//                .storeDurably() //必须调用该方法，添加任务
//                .build();
//        return JobDetail;
//    }

//    @Bean
//    public Trigger messageTrigger(){
//        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 1/1 * * * ?"); //配置任务频率
//
//        Trigger trigger = TriggerBuilder.newTrigger()
//                .forJob(crawlerDetail())
//                .withSchedule(cronScheduleBuilder) //对触发器配置任务
//                .build();
//
//        return trigger;
//    }
}
